package game;

import core.buffer.Buffer;
import core.net.Connection;
import core.net.protocol.IProtocol;
import core.net.protocol.Protocol;
import net.ConcurrentQueue;


public class Player {

    private Connection _connection;
    private int _lifeTime;
    public ConcurrentQueue<IProtocol> cmds = new ConcurrentQueue<>();

    public void connection(Connection connection) {
        _connection = connection;
        _connection.receiveHandler(this::handle);
        _connection.open();
    }

    public void send(IProtocol protocol) {
        _connection.write(Protocol.instance().serialize(protocol));
    }
    public void send(Buffer buffer) {
        _connection.write(buffer);
    }
    private void handle(Buffer buffer) {
        IProtocol cmd = Protocol.instance().deserialize(buffer);
        cmds.enqueue(cmd);
    }

}
